package com.yzd.learnjava.concurrency;

import java.util.concurrent.TimeUnit;

import com.yzd.learnjava.util.Print;

public class SimpleDaemons implements Runnable {
	public void run() {
		try {
			while(true) {
				TimeUnit.MILLISECONDS.sleep(100);
				Print.print(Thread.currentThread() + " " + this);
			}
		} catch (Exception e) {
			Print.print("sleep() interupted");
		}
	}
	public static void main(String[] args) throws Exception {
		for(int i = 0 ; i < 10; i++) {
			Thread daemon = new Thread(new SimpleDaemons());
			daemon.setDaemon(true);
			daemon.start();
		}
		
		Print.print("All daemons started");
		TimeUnit.MILLISECONDS.sleep(175);
	}
}
